package com.wl.mr.speak;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SpeakMapper extends Mapper<LongWritable, Text,Text,SpeakBean> {
    Text k = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");

        String deviceId = fields[1];
        String selfDuration = fields[fields.length - 3];
        String thirdDuration = fields[fields.length - 2];

        SpeakBean bean = new SpeakBean(Long.parseLong(selfDuration), Long.parseLong(thirdDuration), deviceId);
        k.set(deviceId);
        context.write(k,bean);

    }
}
